<template>
  <div class="app-container">
    <el-form :model="selectForm" ref="queryForm" :inline="true">
      <el-form-item label="所属公司">
        <treeselect style="width: 199px;height: 32px" v-model="selectForm.companyId" :options="company"
                    placeholder="请选择所属公司"/>
      </el-form-item>
      <el-form-item label="变卖单号">
        <el-input
          v-model="selectForm.soldCode"
          placeholder="请输入变卖单号"
          clearable
          size="small"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="申请人">
        <el-input
          v-model="selectForm.applyUser"
          placeholder="请输入申请人"
          clearable
          size="small"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="审核状态">
        <el-select
          v-model="selectForm.verifyStatus"
          placeholder="审核状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="时间">
        <el-date-picker
          v-model="selectDate"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-checkbox v-model="selectForm.checked">我审核的</el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="">搜索</el-button>
        <el-button type="success" icon="el-icon-plus" size="mini" @click="add">添加</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list" stripe>
      <el-table-column align="center" type="index" label="序号" width="55"/>
      <el-table-column align="center" label="变卖单号" property="soldCode" width="150">
        <template slot-scope="scope" >
          <span style="color: #2196F3;cursor: pointer" @click="details(scope.row)">{{scope.row.soldCode}}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请人" property="applyUser" :show-overflow-tooltip="true"/>
      <el-table-column label="申请日期" property="applyDate" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ parseTime(scope.row.applyDate) }}
        </template>
      </el-table-column>
      <el-table-column label="涉及设备" property="deviceId"></el-table-column>
      <el-table-column label="变卖理由" property="sellInfo" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="当前节点" property="node" :show-overflow-tooltip="true"/>
      <el-table-column align="center" label="审核状态" property="verifyStatus" :show-overflow-tooltip="true">
        <template slot-scope="scope" style="text-align: center">
          <div class="status green" style="" v-show="scope.row.verifyStatus=='1'">进行中</div>
          <div class="status purple" v-show="scope.row.verifyStatus=='2'">已结束</div>
          <div class="status red" v-show="scope.row.verifyStatus=='3'">未提交</div>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-refresh-right"
            v-show="scope.row.verifyStatus=='2'"
            @click="handleDelete(scope.row)">撤销
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="selectForm.pageNum"
      :limit.sync="selectForm.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import {treeselect} from "@/api/system/dept";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  export default {
    components: {
      Treeselect,
    },
    name: "equipmentSold.vue",
    data() {
      return {
        selectForm: {
          pageNum: 1,
          pageSize: 10,
          companyId: undefined,
          soldCode: '',//报废单号
          applyUser: '',
          verifyStatus: '',
          checked: true
        },
        company: '',
        selectDate: '',
        statusOptions: [
          {value: '1', label: '进行中'},
          {value: '2', label: '已结束'},
          {value: '3', label: '未提交'}],
        loading: false,
        total:2,
        list: [{
          soldCode:'MZ20200520',
          deviceId:'11',
          applyDate:'2020-05-20',
          purchaseDate:'2020-05-20',
          scrapDate:'2020-05-20',
          applyUser:'管理员',
          sellInfo:'原因',
          node:'测试',
          verifyStatus:'1',
          verifyEndDate:'2020-05-20'
        }, {
          soldCode:'MZ20200520',
          deviceId:'11',
          applyDate:'2020-05-20',
          purchaseDate:'2020-05-20',
          scrapDate:'2020-05-20',
          applyUser:'管理员',
          sellInfo:'原因',
          node:'测试',
          verifyStatus:'2',
          verifyEndDate:'2020-05-20'
        }],
      }
    },
    created() {
      this.getTree()

    },
    methods: {
      //所属部门下拉
      getTree() {
        treeselect().then(response => {
          this.company = response.data;
        });
      },
      getList(){

      },
      add(){
        this.$router.push({path:'/equipmentCZ/equipmentSoldEdit'});
      },
      details(row){
        this.$router.push({path:'/equipmentCZ/equipmentSoldDetail',query:{data:row}});
      },
      //删除
      handleDelete(index,row){
        this.$confirm('确定撤销该数据吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '撤销成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消撤销'
          });
        });
      },
    }
  }
</script>

<style scoped>
  .status{
    color: white;
    width: 54px;
    height: 22px;
    display: inline-block
  }
  .green{
    background: #78BF34;
  }
  .purple{
    background:#9E71DC
  }
  .red{
    background: red;
  }
</style>
